package com.tech.pattern.factory.factoryfunc.reflect;

/**
 * @Description: 具体的工厂类，用来生产产品
 * @Author: zl
 * @Date: 2019/9/25 10:36
 */
public class ConcreteCreator implements Creator {
    @Override
    public <T extends ConcreteProduct> T createProduct(Class<T> c) {
        Product product = null;

        try {
            // 通过反射在运行过程中创建类的实例对象
           // product = c.newInstance();
            product = (Product) Class.forName(c.getName()).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }


        return (T) product;
    }
}
